package com.xxx.yuedong.community.schedule;

import com.xxx.yuedong.community.service.DynamicLikeService;
import com.xxx.yuedong.community.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 动态点赞的计划任务
 *
 * @Author YinXi
 * @Versin 1.0.0
 * @Date 2023/8/25
 */
@Component
public class YueDongSchedule {
    @Autowired
    private DynamicLikeService dynamicLikeService;
    @Autowired
    private FollowService followService;

    @Scheduled(cron = "0/${yuedong.dynamic.redisflushtime.like} * * * * *")
    public void rebulidDynamicLikeCache() {
        dynamicLikeService.rebulidDynamicLikeCache();
    }
    @Scheduled(cron = "0 0/${yuedong.dynamic.redisflushtime.like-list} * * * *")
    public void rebulidDynamicCache() {
//        获取当前缓存中喜欢列表的keys
        Set<String> list = dynamicLikeService.getDynamicLikeKeys("dynamic:like:list:*");
//        删除下次点击时重新加载
        dynamicLikeService.rebulidDynamicCache(list);
    }
    @Scheduled(cron = "0/${yuedong.follow.redisflushtime.follow-time} * * * * *")
    public void rebulidFollowListCache() {
        followService.rebulidFollowList();
    }
}
